package com.prodavalnik.model;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class testDB
 */
@WebServlet("/VisualizePictureWithName")
public class VisualizePictureWithName extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public VisualizePictureWithName() {
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String nameOfAPicture = (String) request.getParameter("name");
		if(nameOfAPicture == null)
			return ;
		
		 
      
		File f = new File(DataBaseController.PATH_TO_DIR_WHERE_IMAGES_ARE_SAVED+"\\"+nameOfAPicture);
		BufferedImage image = ImageIO.read(f);
		
		ImageIO.write(image,"jpg", response.getOutputStream());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
	public static void main(String[] args) throws MalformedURLException {
		
			}
}
